package common.hash;

public class Duphash {

    public boolean duplicated(int k, int[] T, int m, int keysChecked[]) {
        int hashOne = hashOne(k, m);
        int hashTwo = hashTwo(k);
        boolean find = false;
        int[] findIndex = new int[m];
        for (int i = 0; ; i++) {
            int hash = (hashOne + i * hashTwo) % m;
            if (T[hash] != -1) {
                for (int j = 0; j < i; j++) {
                    if (findIndex[j] == hash) {
                        break;
                    }
                }
                keysChecked[i] = T[hash];
                findIndex[i] = hash;
            } else {
                find = true;
                break;
            }
        }

        return find;
    }

    private int hashOne(int k, int m) {
        return k % m;
    }

    private int hashTwo(int k) {
        return 7 - k % 7;
    }
}
